package Text9;
import java.util.Scanner;
public class Main {
    public static int N = 1010;
    public static int[] v = new int[N];
    public static int[] w = new int[N];
    public static int[][] f = new int[N][N];
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        for (int i = 1; i <= n; i++) {
            v[i] = in.nextInt();
            w[i] = in.nextInt();
        }
        for (int i = 1; i <=n ; i++) {
            for (int j = 1; j <=m ; j++) {
                f[i][j]=f[i-1][j];
                if(j>=v[i]){
                    f[i][j]=Math.max(f[i][j],f[i][j-v[i]]+w[i]);
                }
            }
        }
        System.out.println(f[n][m]);
    }
}

